<?php
class Application_Model_Report
{
	private $objDb, $m_cache;
	private static $_instance = null;

	public function __construct()
	{
		$this->objDb = Zend_Registry::get('db');
		$this->m_cache = Zend_Registry::get('cache');
	}

	public static function getInstance()
	{
		if (null === self::$_instance) self::$_instance = new self();
		return self::$_instance;
	}

	/**
	 * @author  Ryan <nguyenhoaivien@yahoo.com>
	 * @date	Oc 18, 2013
	 * @param	int type (0: jobs, 1: resumes, 2: jobseekers), string from_date, string to_date
	 * @return array or string
	 * @desc: return update/new data
	 */
	public function getUpdateData($type, $from_date, $to_date)
	{
		try
		{
			return $this->objDb->select('*')->from('data_log_update')
					->where('date >= ?'.$from_date)
					->where('date <= ?'.$to_date)
					->order(array('date'))->query()->fetchAll();
		}
		catch (Exception $e)
		{
			throw new Exception($e);
		}
	}

	/**
	 * @author  Ryan <nguyenhoaivien@yahoo.com>
	 * @date	Oc 18, 2013
	 * @param	int type (0: jobs, 1: resumes, 2: jobseekers), string from_date, string to_date
	 * @return array or string
	 * @desc: return update/new data
	 */
	public function updateReport()
	{
		try
		{
			return $this->objDb->select('*')->from('data_log_update')
					->where('date >= ?'.$from_date)
					->where('date <= ?'.$to_date)
					->order(array('date'))->query()->fetchAll();
		}
		catch (Exception $e)
		{
			throw new Exception($e);
		}
	}

	public function crawlerStatics()
	{
		$time = time() - 60*60*24*30;
		$strSql = 'SELECT active_date, owner, count( id ) AS items FROM jobs GROUP BY active_date, owner ORDER BY active_date ASC , owner where created > = '.$time;
		return $this->objDb->query($strSql)->fetchAll();
	}
}